package org.example.demo3.common;

import org.example.demo3.info.Responseinfo;
import org.example.demo3.mapper.Articlemapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
//评论树算法
@Component
public class Response_Tree {
    @Autowired
    private Articlemapper articlemapper;
    public HashMap<Object,Object> response_tree_cons (int responseid){
        HashMap<Object,Object> hashMap=new HashMap<>();
        List<Responseinfo> list=articlemapper.response_tree_cons(responseid);
        if (list!=null){
            for (Responseinfo responseinfo:list){
                HashMap<Object,Object> map_key=new HashMap<>();
                map_key.put(responseinfo.getId(),responseinfo.getResponsecontent()+"="+responseinfo.getResponsename()+"="+articlemapper.by_id_find_response(responseinfo.getResponseid()).getResponsename());
                HashMap<Object,Object> map_value=response_tree_cons(responseinfo.getId());
                hashMap.put(map_key,map_value);
            }
            return hashMap;
        }else {
            return null;
        }
    }
}
